// If you are in "stata" folder, type:
use ../data/data_final.dta, clear


// Keep only electoral years (1994, 1998, 2002, 2006, 2010, 2014) 
drop if elecyear != 1
// Set time series and cross section
xtset uf_cod year
// Generate lags
**  Incumbent vote in the previous election
gen l4vote = l4.elecvote
**  Previous incumbent vote in the previous election
gen l4votesh = l4.vote_share
// Generate interaction
** State unemployment and industry+services 
gen un_ind1 = ind_ser*unempch_uf
** Benchmark unemployment and industry+services 
gen un_ind2 = ind_ser*unempch_rel
** State unemployment and taxes
gen un_tax1 = tax*unempch_uf
** Benchmark unemployment and taxes
gen un_tax2 = tax*unempch_rel
// Keep only included observations
drop if included != 1

// INTERACTIVE MODEL 1 , state unemployment and with interaction with labor intesity
qui reg vote_share l4vote incumbent c.unempch_uf##c.ind_ser tax if included == 1, vce(cluster uf)
eststo m1_interaction_labor
// INTERACTION MODEL 2, benchmark unemployment and with interaction with labor intensity
qui reg vote_share l4vote incumbent c.unempch_rel##c.ind_ser tax if included == 1, vce(cluster uf)
eststo m2_interaction_labor
// INTERACTION MODEL 3, state unemployment and with interaction with taxes
qui reg vote_share l4vote incumbent c.unempch_uf##c.tax ind_ser if included == 1, vce(cluster uf)
eststo m3_interaction_taxes 
// INTERACTION MODEL 4, benchmark unemployment and with interaction with taxes
qui reg vote_share l4vote incumbent c.unempch_rel##c.tax ind_ser if included == 1, vce(cluster uf)
eststo m4_interaction_taxes 

/// EXPORTING TABLE
#d;
esttab m1_interaction_labor m2_interaction_labor m3_interaction_taxes m4_interaction_taxes using table2.rtf, replace
cells(b (star fmt(3)) se(par fmt(2)))
varlabels(vote_share "VOTE SHARE(t)"
      l4vote "VOTE SHARE(t-1)"
	  incumbent "INCUMBENT"
	  ind_serv "(INDUSTRY+SERVICES)/GDP)"
	  unempch_uf "UNEMPLOYMENT"
	  tax "TAX REVENUE/CURRENT REVENUE"
	  _cons "CONSTANT")
nomtitle title("Table 2")
label
stats(r2 N rmse,  fmt(4 0 4) labels("R squared" "No. of obs." "Root Mean Square Errors"))
starlevels(* 0.10 ** 0.05 *** 0.01)
collabels(none) stardetach legend
note ("Clustered standard errors in parenthesis.")
;


set seed 1234

** Clarify Calculations for Labor Intensity

estsimp reg vote_share l4vote incumbent unempch_uf ind_ser un_ind1 tax if included == 1, vce(cluster uf)

** unemployment at 1.4902025  (1 SD)
setx l4vote 50 incumbent 1 unempch_uf 1.5 tax 51.5 ind_ser 80 un_ind1 120
simqi, ev level(95)

** unemployment at -2.1274255(1 SD)
setx l4vote 50 incumbent 1 unempch_uf -2.1274255 tax 51.5 ind_ser 80 un_ind1 -170.19404
simqi, ev level(95)

drop b1 b2 b3 b3 b4 b5 b6 b7 b8


** Clarify Calculations for Fiscal Autonomy

set seed 1234

estsimp  reg vote_share unempch_uf tax un_tax1 l4vote incumbent ind_ser if included == 1, vce(cluster uf)

** unemployment at 1.5  (1 SD)
setx l4vote 50 incumbent 1 unempch_uf 1.5 tax 70 ind_ser 70 un_tax1  105
simqi, ev level(90)

** unemployment at -2.13(1 SD)
setx l4vote 50 incumbent 1 unempch_uf -2.1274255 tax 70 ind_ser 70 un_tax1 -148.91979
simqi, ev level(90)

drop b1 b2 b3 b3 b4 b5 b6 b7 b8
